package com.xique.park.controller.web;

import com.xique.common.core.enums.CommandSyncCmd;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.domain.PageResult;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.request.web.ipc.CommandListRequest;
import com.xique.park.bean.request.web.ipc.DevDownAllRequest;
import com.xique.park.bean.request.web.ipc.DevInitRequest;
import com.xique.park.service.command.service.IParkIpcCommandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 相机命令controller
 *
 * @author xique
 */
@RestController
@RequestMapping("/web/command")
public class WebParkIpcCommandController {

    @Autowired
    private IParkIpcCommandService parkIpcCommandService;

    /**
     * 一键初始化
     */
    @PreAuthorize(hasPermi = "park:ipc:init")
    @Log(title = "一键初始化", businessType = BusinessType.COMMAND)
    @PostMapping("/devInit")
    public AjaxResult editParkCar(@Validated @RequestBody DevInitRequest request) {
        return parkIpcCommandService.devInit(request.getDevCode());
    }

    /**
     * 一键同步数据
     */
    @PreAuthorize(hasPermi = "park:ipc:downAll")
    @Log(title = "一键同步数据", businessType = BusinessType.COMMAND)
    @PostMapping("/downAll")
    public AjaxResult downAll(@Validated @RequestBody DevDownAllRequest request) {
        return parkIpcCommandService.downAll(request);
    }

    /**
     * 获取可以同步的类型列表
     */
    @PreAuthorize(hasPermi = "park:ipc:downAll")
    @Log(title = "获取可以同步的类型列表", businessType = BusinessType.COMMAND)
    @GetMapping("/downAllList")
    public AjaxResult downAllList() {
        return AjaxResult.success(CommandSyncCmd.getList());
    }

    /**
     * 查询相机命令列表
     */
    @PostMapping("/list")
    @PreAuthorize(hasPermi = "park:command:list")
    public AjaxResult commandList(@Validated @RequestBody CommandListRequest request) {
        PageResult pageResult = parkIpcCommandService.getCommandInfoList(request);
        return AjaxResult.success(pageResult);
    }

}
